<?php
require ("../global.inc.php");

class ShowArticle extends CommonFrameWork{

	/**
	 * 文章对象
	 *
	 * @var obj
	 */
	var $obj_article;

	function main(){
		/**
		 * 创建文章对象
		 */
		if (!is_object($this->obj_article)){
			require_once("article.class.php");
			$this->obj_article = new ArticleClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("home");

		/**
		 * 语言包
		 */
		$this->getlang("article");

		switch ($this->_input['action']){
			case "list":
				$this->_listarticle();
				break;
			case "view":
				$this->_viewarticle();
				break;
			default:
				$this->_listarticle();
				break;
		}

	}

	/**
	 * 文章列表
	 *
	 */
	function _listarticle(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 取得查询参数
		 */
		$obj_condition[key] = $this->_input['keyword'];
		$obj_condition[keygenre] = $this->_input['searchtype'];

		/**
		 * 取得文章列表
		 */
		$obj_page->pagebarnum(15);
		$article_array = $this->obj_article->getArticleList($obj_condition, $obj_page);
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		$this->output("page_list", $page_list);
		$this->output("article_array", $article_array);
		$this->showpage("article.list");
	}
	/**
	 * 文章添加页面
	 *
	 */
	function _viewarticle(){
		$article_id = $this->_input['articleid'];
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["articleid"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errArticleId']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$article_row = $this->obj_article->getArticleRow($article_id);
			$this->output("article_row", $article_row);
			$this->showpage("article.view");
		}

	}

}

$article = new ShowArticle();
$article->main();
unset($article);

?>